package indi.kider.server.woniubus.api;

import indi.kider.common.model.employee.Employee;
import indi.kider.common.model.woniubus.DestineTenant;
import indi.kider.common.model.woniubus.TenantInHouseVo;
import indi.kider.common.model.woniubus.TinHouseTenantVo;
import indi.kider.server.woniubus.service.PartService;
import indi.kider.server.woniubus.service.related.AuthcService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import pers.vankid.common.model.base.CommonResponse;
import pers.vankid.common.utils.page.PageRequest;
import pers.vankid.common.utils.page.PageResponse;

import java.util.List;
import java.util.Map;

/**
 * part
 * 二期业务接口
 */
@RestController
@RequestMapping(value = "part")
public class PartController {


    @Autowired
    AuthcService authcService;
    @Autowired
    PartService partService;
    /**
     * @apiDescription 根据准租客列表（分页）
     * @param request
     * @return
     */
    @PostMapping("/getTenantInHouseList")
    public CommonResponse<PageResponse<List<Map>>> getTenantInHouseList(@RequestBody PageRequest<TenantInHouseVo> request) {
        try {
            Employee employee = authcService.getCurrentUser().getData();
            request.getQuery().setEmployeePartId(employee.getId());
            return CommonResponse.buildGetSuccessResponse(partService.getTenantInHouseList(request));
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }

    /**
     * @api {PUT} /tenantCheckIn
     * @apiGroup part
     * @apiDescription 准租客入住
     * @apiParamExample 请求样例：
     * http://localhost:9002/woniubus/part/tenantCheckIn
     * {id:,state}
     * @apiSuccessExample {json} 返回样例:
     * {"status": "202","msg": "保存成功！","data": ""}
     */
    @PutMapping("/tenantCheckIn")
    public CommonResponse tenantCheckIn(@RequestBody TinHouseTenantVo tinHouseTenantVo) {
        try {
            Employee employee = authcService.getCurrentUser().getData();
            tinHouseTenantVo.getTenantVo().setOpInId(employee.getId());
            partService.tenantCheckIn(tinHouseTenantVo.getTenantInHouse(),tinHouseTenantVo.getTenantVo());
            return CommonResponse.buildUpdateSuccessResponse("提交成功");
        } catch (Exception e) {
            return CommonResponse.buildExceptionResponse(e);
        }
    }
}
